﻿using EMRView;
using EMRView.Extensions.Extension;
using HC.View;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace HCView.Extensions.Command.Test
{
    public partial class CommandDome : Form
    {
        public CommandDome()
        {
            InitializeComponent();
        }

        private void CommandDome_Load(object sender, EventArgs e)
        {
            hccc_Main.HCEmrView = hev_Main;
            hev_Main.ReadOnly = true;
            hev_Main.OnSectionPaintPaperBefor += (s, aPageIndex, aRect, aCanvas, aPaintInfo) =>
            {
                if ((!aPaintInfo.Print) && (s as HCSection).ReadOnly)
                {
                    aCanvas.Font.BeginUpdate();
                    try
                    {
                        aCanvas.Font.Size = 48;
                        aCanvas.Font.Color = Color.Gray;
                        aCanvas.Font.Family = "隶书";
                    }
                    finally
                    {
                        aCanvas.Font.EndUpdate();
                    }
                    aCanvas.TextOut(aRect.Left, aRect.Top, "只读");
                }
            };
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {

        }


        private void toolStripButton9_Click(object sender, EventArgs e)
        {
            DeEdit deEdit = new DeEdit(hev_Main.ActiveSectionTopLevelData(), "");
            HC.View.BorderSide s = 0;
            s = s | BorderSide.cbsBottom;
            deEdit.BorderSides.Value = (byte)(s);
            deEdit.PrintOnlyText = false;//打印边框
            deEdit[DeProp.Index] = "DE11";
            deEdit[DeProp.Name] = "测试";
            deEdit.Width = 100;

            //var sNum = hev_Main.GetActiveItem().StyleNo;
            //deEdit.Height = hev_Main.Style.TextStyles[sNum].TextMetric_tmHeight;
            hev_Main.InsertItem(deEdit);

            //var item = hev_Main.NewDeItem("测试病历元素");
            //item[DeProp.Index] = "DE11";
            //item[DeProp.Name] = "测试";
            //hev_Main.InsertDeItem(item);

            //DeCheckBox radio = new DeCheckBox(hev_Main.ActiveSectionTopLevelData(), "111111111", true);
            //radio[DeProp.Index] = "DE11";
            //radio.Checked = false;
            //hev_Main.InsertItem(radio);

            //DeGroup vDeGroup = new DeGroup(hev_Main.ActiveSectionTopLevelData());
            //vDeGroup[DeProp.Index] = "DE11";
            //vDeGroup[DeProp.Name] = "测试";
            //hev_Main.InsertDeGroup(vDeGroup);

            //hev_Main.InsertSectionBreak();

            //hev_Main.BeginUpdate();
            //var section = new HCSection(hev_Main.Style);
            ////section["Index"] = "123456";
            //section.Propertys["Id"] = "";
            //hev_Main.Sections.Add(section);
            //hev_Main.EndUpdate();

            //var count = hev_Main.Sections.Count;
            //StringBuilder vStrings = new StringBuilder();
            //vStrings.Append("Name=病程");
            //vStrings.Append("创建者=" + 1);
            //vStrings.Append("创建时间=" + DateTime.Now);
            //var index = "测试病程" + (ccount == 0 ? "" : ccount.ToString());
            //hev_Main.InsertProc(index, vStrings.ToString(), "");
            //hev_Main.EditProcIndex = "";//设置当前页面可以编辑的病程Index，除了这个index的病程都将无法编辑
            //ccount++;
        }

        string xml = "";

        private void toolStripButton10_Click(object sender, EventArgs e)
        {
            var xml = hev_Main.GetXml();
            //xml = hev_Main.GetXml();
            //hev_Main.Clear();
            //var list = hev_Main.GetHCCustomItem("测试病程");
            //foreach (var item in list)
            //{
            //    var g = (item as DeGroup);
            //    g.ReadOnly = true;
            //}
            //var list = hev_Main.GetHCCustomItem("DE11");
            //list[0].Active = true;

            //hev_Main.Style.UpdateInfoReScroll();

            //MessageBox.Show(list.Count.ToString());
            //string text = "";
            ////hev_Main.GetDeItemText("DE10", ref text);
            ////MessageBox.Show(text);

            ////hev_Main.GetDeItemText("DE11", ref text);
            ////MessageBox.Show(text);
            //int startNo = 0;
            //int endNo = 0;

            //hev_Main.GetDataDeGroupItemNo(hev_Main.ActiveSection.Page, "DE11", false, ref startNo, ref endNo);
            //text = hev_Main.GetDataDeGroupText(hev_Main.ActiveSection.Page, startNo, hev_Main.ActiveSection.Page.GetDomainAnother(startNo));

            //MessageBox.Show(text);
        }

        private void toolStripButton15_Click(object sender, EventArgs e)
        {
            var item = hev_Main.NewDeItem("测试病历元素");
            item[DeProp.Index] = "DE11";
            item[DeProp.Name] = "测试";
            hev_Main.InsertDeItem(item);
        }

        private void hev_Main_MouseUp(object sender, MouseEventArgs e)
        {
        }

        private void hev_Main_MouseDown(object sender, MouseEventArgs e)
        {

            if (e.Button == MouseButtons.Right)
            {

            }
        }
    }
}
